// https://leetcode-cn.com/problems/valid-sudoku/
class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        // 二进制标记法
        // 由点坐标计算到大宫格的坐标
        int x[9] = {0}, y[9] = {0}, z[9] = {0};
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.') continue;
                int d = board[i][j] - '0';
                if (x[i] & (1 << d)) return false;
                if (y[j] & (1 << d)) return false;
                if (z[i / 3 * 3 + j / 3] & (1 << d)) return false;
                x[i] |= (1 << d);
                y[j] |= (1 << d);
                z[i / 3 * 3 + j / 3] |= (1 << d);
            }
        }
        return true;
    }
};